<template>
     <div class="mui-numbox" data-numbox-min='1' style="height:25px;width:100px;padding:0  30px;">
    <button class="mui-btn mui-btn-numbox-minus" type="button" style="width:30px;">-</button>
    <input id="test" class="mui-input-numbox" type="number" :value="initcount" @change="countChanged" ref="numbox" />
    <button class="mui-btn mui-btn-numbox-plus" type="button"  style="width:30px;">+</button>
  </div>
</template>
<script>
import mui from '../../../lib/mui/js/mui.min.js'
export default {
     mounted() {
    // 初始化数字选择框组件
    mui(".mui-numbox").numbox().getValue();
  },
  methods: {
      countChanged(){
          console.log(this.$refs.numbox.value,12132);
          //向父元素传递数量
          this.$emit('getcount',parseInt(this.$refs.numbox.value))

         this.$store.commit('updateinfo',{
           id:this.goodsid,
           count:this.$refs.numbox.value
         })
      },

  },
  watch: {
    //限制最大数量  根据父元传过来的
    max:function(newVal,oldVal){
      mui('.mui-numbox').numbox().setOption('max',newVal)
    }
  },
     /* 定义属性  接受父组件传的值 */
  props:['initcount',"goodsid",'max']
}
</script>
<style lang="scss" scoped>

</style>
